/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Facades;

import Entities.Student;
import Entities.User;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

//Para obtener el usuario a partir del id.
/**
 *
 * @author roycalderon
 */
@Stateless
public class StudentFacade extends AbstractFacade<Student> {

    @PersistenceContext(unitName = "MaRoY-LibraryPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public StudentFacade() {
        super(Student.class);
    }
    private User entity_User;
    private UserFacade ejbFacade_User;

    /**
     * Este es el metodo que me devuelve los datos del estudiante...
     *
     * @author roycalderon
     */
    public Student FindbyUser(User entidadUser) {
        Query query = em.createNamedQuery("Student.findByUser_id");
        query.setParameter("userid", entidadUser);
        Student aux;
        try {
            aux = (Student) query.getSingleResult();
            if (aux != null) {
                return aux;
            } else {
                return null;
            }
        } catch (Exception e) {
            return null;
        }
    }

    //Encuentra y devuelve al Studiante por su cedula... 
    public Student FindbyidNumberStudent(String cedula) {
        Query query = em.createNamedQuery("Student.findByIdNumber");
        query.setParameter("idNumber", cedula);
        Student aux;
        try {
            aux = (Student) query.getSingleResult();
            if (aux != null) {
                return aux;
            } else {
                return null;
            }
        } catch (Exception e) {
        }
        return null;
    }
}
